package leetcode.D100.T83;

import util.ListNode;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */


class Solution {
    // 一刷
    /*public ListNode deleteDuplicates(ListNode head) {
        if(head == null) return head;
        ListNode i = head, j = head;
        while(j != null) {
            if(j.val != i.val) {
                i.next = j;
                i = i.next;
            }
            j = j.next;
        }
        i.next = null;
        return head;
    }*/

    // 二刷
    public ListNode deleteDuplicates(ListNode head) {
        ListNode i = head, j = head;
        while(i != null) {
            while(j != null && j.val == i.val) {
                j = j.next;
            }
            i.next = j;
            i = i.next;
        }
        return head;
    }
}
